import { ListNode } from "./ListNode.mjs";
/**
 * https://leetcode.cn/problems/reverse-linked-list/description/?envType=study-plan-v2&envId=top-100-liked
 * 输入：head = [1,2,3,4,5]
输出：[5,4,3,2,1]
 * @param {ListNode} head
 * @return {ListNode}
 */
var reverseList = function (head) {
  if (!head) return null;
  let pre = null;
  let cur = head;
  while (cur) {
    let next = cur.next;
    cur.next = pre;
    pre = cur;
    cur = next;
  }
  return pre;
};
const node = new ListNode(2, new ListNode(5));
console.log(reverseList(node));
